<?php

class NewsController extends Controller
{
	public function actionIndex()
	{
      $criteria = new CDbCriteria();
      $criteria->addCondition('news_active = 1');
      $criteria->offset = 0;
      $criteria->addCondition('news_type = 0'); // Tin tức
      $list_news_newest = array(); // Danh sach tin moi nhat
      $list_news_most_read = array(); // Danh sach tin nhieu nguoi doc
      
      $criteria->limit = 8;
      $criteria->order = 'news_id DESC';
      $list_news_newest = News::model()->findAll($criteria);
      
      $criteria->limit = 5;
      $criteria->order = 'news_view DESC';
      $list_news_most_read = News::model()->findAll($criteria);
      //CVarDumper::dump($list_news_most_read,10,true);die();
      
      $this->render('index',array(
         'list_news_newest' => $list_news_newest,
         'list_news_most_read' => $list_news_most_read,
      ));
	}
   
   public function actionProject(){
      $page = isset($_GET['page']) ? ((int) $_GET['page']) : 1;
      $limit = 10;
      $offset = $page*$limit - $limit;
      
      $criteria = new CDbCriteria();
      $criteria->addCondition('news_active = 1');
      $criteria->offset = $offset;
      $criteria->limit = $limit;
      $criteria->addCondition('news_type = 1'); // Dự án
      $list_news_newest = array(); // Danh sach tin moi nhat
      
      $criteria->limit = 10;
      $criteria->order = 'news_id DESC';
      
      $list_news_newest = News::model()->findAll($criteria);
      $count = News::model()->count($criteria);
      $pagination = new Zebra_Pagination();
      $pagination->records($count);
      $pagination->records_per_page($limit);
      $this->pageTitle = 'Dự án đã triển khai';
      $this->render('other',array(
         'list_news_newest' => $list_news_newest,
         'pagination' => $pagination,
      ));
   }
   
   public function actionGeomancy(){
      $page = isset($_GET['page']) ? ((int) $_GET['page']) : 1;
      $limit = 10;
      $offset = $page*$limit - $limit;
      
      $criteria = new CDbCriteria();
      $criteria->addCondition('news_active = 1');
      $criteria->offset = $offset;
      $criteria->limit = $limit;
      $criteria->addCondition('news_type = 2'); // Phong thủy
      $list_news_newest = array(); // Danh sach tin moi nhat
      
      $criteria->limit = 10;
      $criteria->order = 'news_id DESC';
      
      $list_news_newest = News::model()->findAll($criteria);
      $count = News::model()->count($criteria);
      $pagination = new Zebra_Pagination();
      $pagination->records($count);
      $pagination->records_per_page($limit);
      $this->pageTitle = 'Phong thủy';
      $this->render('other',array(
         'list_news_newest' => $list_news_newest,
         'pagination' => $pagination,
      ));
   }
   public function actionDetail(){
      
      $id = Yii::app()->request->getParam('id',0);
      $model = News::model()->findByPk($id);

      if($model != null)
         $this->pageTitle = $model->news_title;
      $this->render('detail',array(
         'model' => $model,
      ));
   }

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}